package enumdemo;

/**
 * Created with IntelliJ IDEA
 * Description
 * User：chenshu
 * Date：2023-11-09
 * Time：09:53
 */
public enum TestEnum {
    RED("红色",1),
    BLACK("黑色",2),
    GREEN("绿色",3),
    YELLOW("黄色",4);

    private final String name;
    private final int index;

    TestEnum(String name, int index) {
        this.name = name;
        this.index = index;
    }

    public static void main3(String[] args) {
        TestEnum color1 = TestEnum.valueOf("GREEN");
        System.out.println(color1.name);
        TestEnum color2 = TestEnum.valueOf("RED");
        System.out.println(color2.compareTo(color1));
    }
    public static void main2(String[] args) {
        TestEnum[] testEnum2 = TestEnum.values();
        for (int i = 0; i < testEnum2.length; i++) {
            System.out.println(testEnum2[i] + " " + testEnum2[i].ordinal());
        }
    }
    public static void main1(String[] args) {
        TestEnum testEnum = TestEnum.YELLOW;
        switch (testEnum) {
            case RED:
                System.out.println("red");
                break;
            case BLACK:
                System.out.println("black");
                break;
            case YELLOW:
                System.out.println("yellow");
                break;
            case GREEN:
                System.out.println("green");
                break;
            default:
                break;
        }
    }
}
